import fetch from 'common/src/utils/fetch';
import UTILS from 'common/src/utils/utils';

/**
 * 培养方案列表查询
 */
export function queryMinorCultureSchemeList(data) {
    return fetch({
        url:
            '/api/cultureservice/minorCultureSchemePre/findMinorCultureSchemePreList',
        method: 'POST',
        data
    });
}

/**
 * 专业下拉内容查询
 */
export function queryProfessionByCollege(data) {
    return fetch({
        url: '/api/cultureservice/minorMajorSup/queryProfession',
        method: 'POST',
        data
    });
}

/**
 * 删除培养方案
 */
export function deleteCultureScheme(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/delCultureScheme',
        method: 'POST',
        data
    });
}

/**
 * 查询培养方案模板（根据学院和专业）
 */
export function queryCultureTemplate(data) {
    return fetch({
        url:
            '/api/cultureservice/minorCultureTemplate/findMinorCultureTemplateListByParams',
        method: 'POST',
        data
    });
}

/**
 * 撤销培养方案
 */
export function revokeCultureScheme(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/revoke',
        method: 'PUT',
        data
    });
}

/**
 * 根据模板id获取模板章节信息
 */
export function getCultureTemplateInfo(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre?templateId=' + data,
        method: 'GET'
    });
}

/**
 * 保存培养方案信息
 */
export function saveCultureSchemeInfo(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/addMinorCultureScheme',
        method: 'POST',
        data
    });
}

/**
 * 修改培养方案信息
 */
export function saveCultureSchemeSectionInfo(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre',
        method: 'POST',
        data
    });
}

/**
 * 根据方案id获取模板章节信息
 */
export function getCultureSectionBySchemeId(data) {
    return fetch({
        url:
            '/api/cultureservice/minorCultureSchemeDetail/getSchemeDetailByCultureId?cultureId=' +
            data,
        method: 'GET'
    });
}

/**
 * 根据方案id获取方案信息
 */
export function getCultureSchemeInfoBySchemeId(data) {
    return fetch({
        url:
            '/api/cultureservice/minorCultureSchemePre/findMinorCultureSchemeById?cultureId=' +
            data,
        method: 'GET'
    });
}

/**
 * 提交辅修培养方案审批
 * @param data
 */
export function checkCultureScheme(data) {
    return fetch({
        url:
            '/api/cultureservice/minorCultureSchemePre/checkMinorCultureSchemePre',
        method: 'post',
        data
    });
}

/**
 * 批量创建培养方案
 * @param data
 */
export function batchCultureScheme(data) {
    return fetch({
        url:
            '/api/cultureservice/minorCultureSchemePre/batchAddMinorCultureScheme',
        method: 'post',
        data
    });
}

/**
 * 轮训查询批量复制进度进度
 * @param data
 */
export function getBatchCopyStatus(data) {
    return fetch({
        url:
            '/api/cultureservice/minorCultureSchemePre/getBatchCulStatus?redisKey=' +
            data,
        method: 'GET'
    });
}

/**
 * 培养计划提交审核
 * @param data
 */
export function checkMinorCulturePlan(data) {
    return fetch({
        url:
            '/api/cultureservice/minorCulturePlan/checkMinorCulturePlan',
        method: 'POST',
        data
    });
}

/**
 * 培养方案导出pdf或者word压缩包
 * @param {Object} params
 */
export function exportCultureSchemePdfOrWordZip(params) {
    const url = '/api/cultureservice/minorCultureSchemePre/exportMinorCultureSchemePdfOrWordZip';
    let queryParams = '';
    for (let item in params) {
      if (params[item] === '') {
        continue;
      }
      queryParams += `${item}=${params[item]}&`;
    }
    queryParams = queryParams.substring(0, queryParams.lastIndexOf('&'));
    window.open(`${url}?${queryParams}`);
  }



// 模板复制功能
export function copyMinorSchemePre(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/copyMinorSchemePre',
        method: 'POST',
        data
    });
}

// yytiand
// 导出pdf
export function exportMinorCultureSchemePdf(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/exportMinorCultureSchemePdf?id='+data+'&language=cn',
        method: 'GET'
    });
}

// 导出word
export function exportMinorCultureSchemeWord(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/exportMinorCultureSchemeWord?id='+data+'&language=cn',
        method: 'GET'
    });
}

// 导出zip
// todo
export function exportMinorCultureSchemePdfOrWordZip(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/exportMinorCultureSchemePdfOrWordZip?id='+data,
        method: 'GET'
    });
}

// 高级导出
export function exportCultureSemesterWord2(id,semester) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/exportCultureSemesterWord2?id='+id+'&semester='+semester,
        method: 'GET'
    });
}

// 查询导出zip
export function exportMinorCultureSchemeZip(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/exportMinorCultureSchemeZip?cultureIds='+data,
        method: 'GET'
    });
}

// 培养方案变更
export function changeCultureScheme(params) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/changeCultureScheme',
        method: 'GET',
        params
    });
}

// 取消变更
export function cancelChangeCultureScheme(params) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/cancelChangeCultureScheme',
        method: 'GET',
        params
    });
}

// 取消变更
export function deleteCultureSchemeList(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/deleteCultureSchemeList',
        method: 'post',
        data
    });
}

export function givenApprovalTaskList(data) {
    return fetch({
        url: '/api/workflow/approval/givenApprovalTaskList',
        method: 'post',
        data
    });
}

export function findSchoolTermByCultureId(params) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/findSchoolTermByCultureId',
        method: 'get',
        params
    });
}

//查找培养方案
export function findCultureSchemeListByYear(params) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/findCultureSchemeListByYear',
        method: 'get',
        params
    });
}

//查找章节信息
export function findCultureSchemeDetailList(params) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemePre/findCultureSchemeDetailList',
        method: 'get',
        params
    });
}